package controller

import (
	"context"
	"net/http"
	"web/global"
	"web/model"
	"web/utils"

	"github.com/gin-gonic/gin"
)

//获取所有地区信息
func GetArea(ctx *gin.Context) {
	resp := make(map[string]interface{})
	defer ctx.JSON(http.StatusOK, resp)
	//获取数据库数据
	areas, err := model.GetArea()
	if err != nil {
		global.GlobalLog.Error(context.Background(), "获取所有地域信息错误:", err)
		resp["errno"] = utils.RECODE_DBERR
		resp["errmsg"] = utils.RecodeText(utils.RECODE_DBERR)
		return
	}
	//把数据返回给前端
	resp["errno"] = utils.RECODE_OK
	resp["errmsg"] = utils.RecodeText(utils.RECODE_OK)
	resp["data"] = areas
}
